﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ProductList.aspx.cs" Inherits="SalesManagement.Modules.List.ProductList" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register Src="~/Controls/List/ProductForm.ascx" TagName="WindowEditor" TagPrefix="uc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Danh sách sản phẩm</title>

    <script language="javascript" type="text/javascript">
        function DocumentReady() {
            var obj = document.getElementById('ResourceManager');
            MethodNamespace.DocumentReady({
                success: function() {
                }
            });
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" DirectMethodNamespace="MethodNamespace">
        <Listeners>
            <DocumentReady Handler="DocumentReady();" Delay="100" />
        </Listeners>
    </ext:ResourceManager>
    <ext:Store ID="storeMain" runat="server" GroupField="CategoryName">
        <Reader>
            <ext:JsonReader IDProperty="ProductId">
                <Fields>
                    <ext:RecordField Name="ProductId" />
                    <ext:RecordField Name="ProductCode" />
                    <ext:RecordField Name="ProductName" />
                    <ext:RecordField Name="CategoryName" />
                    <ext:RecordField Name="CategoryId" />
                    <ext:RecordField Name="OutUnit" />
                    <ext:RecordField Name="InputUnit" />
                    <ext:RecordField Name="StockUnit" />
                    <ext:RecordField Name="OutputPrice" />
                    <ext:RecordField Name="InputPrice" />
                    <ext:RecordField Name="StockPrice" />
                    <ext:RecordField Name="Description" />
                    <ext:RecordField Name="IsWarranty" />
                    <ext:RecordField Name="IsActive" />
                    <ext:RecordField Name="Deleted" />
                    <ext:RecordField Name="CreatedDate" />
                    <ext:RecordField Name="CreatedBy" />
                    <ext:RecordField Name="UpdatedDate" />
                    <ext:RecordField Name="UpdatedBy" />
                    <ext:RecordField Name="MinStock" />
                    <ext:RecordField Name="MaxStock" />
                    <ext:RecordField Name="WarehouseId" />
                    <ext:RecordField Name="InUnitName" />
                    <ext:RecordField Name="OutUnitName" />
                    <ext:RecordField Name="StockUnitName" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Viewport ID="Viewport1" runat="server" Layout="border">
        <Items>
            <ext:GridPanel ID="grdMain" runat="server" AutoExpandColumn="ProductName" Border="false"
                Region="Center" StoreID="storeMain" TrackMouseOver="true"
                StripeRows="true">
                <TopBar>
                    <ext:Toolbar ID="tbMain" runat="server">
                        <Items>
                            <ext:ToolbarSpacer />
                            <ext:Button ID="btnAdd" runat="server" Text="Tạo mới" Icon="TableAdd">
                                <DirectEvents>
                                    <Click OnEvent="btnAdd_Click" />
                                </DirectEvents>
                            </ext:Button>
                            <ext:ToolbarSpacer />
                            <ext:ToolbarFill />
                            <ext:TextField ID="txtKeyword" runat="server" EmptyText="Tìm kiếm" />
                            <ext:ToolbarSpacer />
                            <ext:Button ID="btnFind" runat="server" Text="Tìm kiếm" Icon="Find" FormBind="true">
                                <DirectEvents>
                                    <Click OnEvent="btnFind_Click" />
                                </DirectEvents>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:RowNumbererColumn />
                        <ext:Column ColumnID="ProductCode" DataIndex="ProductCode" Header="Mã hàng" />
                        <ext:Column ColumnID="ProductName" DataIndex="ProductName" Header="Tên hàng" />
                        <ext:Column ColumnID="InUnitName" DataIndex="InUnitName" Header="Đơn vị nhập" />
                        <ext:Column ColumnID="OutUnitName" DataIndex="OutUnitName" Header="Đơn vị xuất" />
                        <ext:Column ColumnID="StockUnitName" DataIndex="StockUnitName" Header="Đơn vị lưu kho" />
                        <ext:Column ColumnID="MinStock" DataIndex="MinStock" Header="Tồn tối thiểu" Align="Right"/>
                        <ext:Column ColumnID="MaxStock" DataIndex="MaxStock" Header="Tồn tối đa" Align="Right"/>
                        <ext:Column ColumnID="CategoryName" DataIndex="CategoryName" Header="Nhóm hàng  " />
                        <ext:Column ColumnID="Decription" DataIndex="Decription" Header="Diễn giải" />
                        <ext:CheckColumn Editable="true" ColumnID="IsActive" DataIndex="IsActive" Header="Kích hoạt" />
                        <ext:CommandColumn Width="80" ButtonAlign="Center">
                            <Commands>
                                <ext:GridCommand Icon="NoteEdit" Text="Cập nhật" CommandName="Edit">
                                </ext:GridCommand>
                            </Commands>
                        </ext:CommandColumn>
                        <ext:CommandColumn Width="60" ButtonAlign="Center">
                            <Commands>
                                <ext:GridCommand Icon="NoteDelete" Text="Xóa" CommandName="Delete">
                                </ext:GridCommand>
                            </Commands>
                        </ext:CommandColumn>
                    </Columns>
                </ColumnModel>
                <View>
                    <ext:GroupingView ID="GroupingView1" HideGroupedColumn="true" runat="server" ForceFit="true"
                        EnableRowBody="true" MarkDirty="false" >
                    </ext:GroupingView>
                </View>
                <DirectEvents>
                    <AfterEdit OnEvent="grdMain_OnAfterEdit">
                        <ExtraParams>
                            <ext:Parameter Name="IsActive" Value="e.record.data.IsActive" Mode="Raw">
                            </ext:Parameter>
                            <ext:Parameter Name="ProductId" Value="e.record.data.ProductId" Mode="Raw">
                            </ext:Parameter>
                        </ExtraParams>
                    </AfterEdit>
                    <Command OnEvent="grdMain_OnCommand">
                        <ExtraParams>
                            <ext:Parameter Name="command" Value="command" Mode="Raw" />
                            <ext:Parameter Name="id" Value="record.data.ProductId" Mode="Raw" />
                        </ExtraParams>
                        <Confirmation ConfirmRequest="true" Message="Bạn có thật sự muốn xóa dòng dữ liệu này không?"
                            Title="Thông báo" BeforeConfirm="if (command=='Edit') return false;" />
                    </Command>
                </DirectEvents>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true" />
                </SelectionModel>
                <BottomBar>
                    <ext:PagingToolbar ID="paddingBar" StoreID="storeMain" runat="server" PageSize="50"
                        DisplayInfo="true" DisplayMsg="Đang xem dòng {0} đến {1} của {2}" EmptyMsg="Không có dữ liệu">
                        <Listeners>
                            <AfterRender Handler="this.refresh" />
                        </Listeners>
                    </ext:PagingToolbar>
                </BottomBar>
            </ext:GridPanel>
        </Items>
    </ext:Viewport>
    <uc:WindowEditor ID="WindowEditor" runat="server" />
    </form>
</body>
</html>
